package net.xo68.destiny.core.eventbus;

import com.lmax.disruptor.EventHandler;
import lombok.extern.slf4j.Slf4j;

import java.util.HashMap;
import java.util.Map;

/**
 * 事件处理路由
 * @author wuxie
 * @version 2020-11-13
 */
@Slf4j
public class EventHandleRouting implements EventHandler<MessageEvent> {
    private final Map<Integer,EventHandler<MessageEvent>> eventHandlerMap= new HashMap<>();

    public void put(int eventType,EventHandler<MessageEvent> eventHandler){
        this.eventHandlerMap.put(eventType,eventHandler);
    }

    @Override
    public void onEvent(MessageEvent messageEvent, long l, boolean b) throws Exception {
        if(this.eventHandlerMap.containsKey(messageEvent.getEventType())){
            this.eventHandlerMap.get(messageEvent.getEventType()).onEvent(messageEvent,l,b);
        }
    }
}
